<?php

/**
 *分类处理函数
 *@param array $data 分类的所有的信息
 */
function getTree($data, $pid = 0, $count = 0)
{
    static $res = array();
    //循环获取每一个数据
    foreach ($data as $val) {
        //var_dump($val);
        if ($val['pid'] == $pid) {
            $val['count'] = $count;
            //var_dump($val);
            $res[] = $val;
            getTree($data, $val['id'], $count + 1);
        }
    }

    return $res;
}
